class Solution {
    public int pivotIndex(int[] nums) {
        /**
        双滑动窗口解法
         */
        int res = -1;
        int leftSum = 0;
        int rightSum = 0;
        for (int i = 0; i < nums.length; i++) {
            rightSum += nums[i];
        }
        for (int i = 0; i < nums.length; i++) {
            rightSum -= nums[i];
            if (leftSum == rightSum) {
                res = i;
                break;
            }
            leftSum += nums[i];
        }
        return res;
        /**
        此方法只考虑了数组每次+都是正数
        如果都是负数，一边一直小，不会找到中间值
        int l = nums.length;
        int left = 0,right = l -1;
        int leftNum = nums[left],rightNum = nums[right];
        while(left < right) {
            if(leftNum < rightNum) {
                left++;
                leftNum += nums[left];
            } else if (leftNum > rightNum) {
                right--;
                rightNum += nums[right];
            } else {
                left++;
                right--;
                leftNum += nums[left];
                rightNum += nums[right];
            }
        }
        if(left == right) {
            return left;
        }
        return -1;
         */
        
    }
}